package com.xyebank.ledger.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	public static Date str2Date(String source) {
		Date date = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
		try {
			date = sdf.parse(source);
			System.out.println(date);
		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		return date;
	}

	public static Date str2Date(String source, String format) throws ParseException {
        Date date = null;
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmSS");
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        date = sdf.parse(source);
        System.out.println(date);
        return date;
    }
	

	public static Date getDate(String source) {
		long lt = new Long(source);
		Date date = new Date(lt);
		return date;
	}

	public static String getStrDate(String source) {

		long lt = new Long(source);
		Date date = new Date(lt);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
		String str = sdf.format(date);
		return str;
	}

	public static String getFormatDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
		String str = sdf.format(date);
		return str;
	}
}
